package com.xiaojun.whut.Controller.User;

import com.alibaba.fastjson.JSON;
import com.xiaojun.whut.Service.PcAdminService;
import com.xiaojun.whut.Service.PcUserService;
import com.xiaojun.whut.annotation.MyLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author 鲁佳磊
 * @create 2020-11-02 23:27
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private PcUserService pcUserService;

    @MyLog("修改密码")
    @RequestMapping("/updatePassword")
    public String updatePassword(@RequestParam("username") String username, @RequestParam("oldpassword") String oldpassword, @RequestParam("newpassword") String newpassword) {
        System.out.println(username + "   " + oldpassword + "   " + newpassword);
        String o = pcUserService.updatePassword(username, oldpassword, newpassword);
        return o;
    }

    @MyLog("增加一个卡片信息")
    @RequestMapping("/addCardInfo")
    public String addCardInfo(@RequestParam("userName") String userName, @RequestParam("phoneNumber") String phoneNumber, @RequestParam("collage") String collage, @RequestParam("label") String label, @RequestParam("descInfo") String descInfo) {

        try {

            String s = pcUserService.addCardInfo(userName, phoneNumber, collage, label, descInfo);
            return s;
        } catch (Exception e) {
            return "100";
        }
    }

    @MyLog("根据label信息，得到卡片信息，而且是最热的信息")
    @RequestMapping("/getCardInfoByLabel")
    public String getCardInfoByLabel(@RequestParam("label") String label){
        System.out.println("访问这个消息");
        try {
            String allCardInfo = pcUserService.getAllCardInfo(label);
            return allCardInfo;
        }catch (Exception e){
            HashMap<String, Object> stringObjectHashMap = new HashMap<>();
            stringObjectHashMap.put("flag",100);
            return JSON.toJSONString(stringObjectHashMap);

        }
    }

    @MyLog("根据label信息，得到卡片信息，而且是最新的信息")
    @RequestMapping("/getCardInfoByLabelMostNew")
    public String getCardInfoByLabelMostNew(@RequestParam("label") String label){
        System.out.println("访问这个消息");
        try {
            String allCardInfo = pcUserService.getAllCardInfoMostNew(label);
            return allCardInfo;
        }catch (Exception e){
            HashMap<String, Object> stringObjectHashMap = new HashMap<>();
            stringObjectHashMap.put("flag",100);
            return JSON.toJSONString(stringObjectHashMap);
        }
    }
    @MyLog("根据修改这个关注数")
    @RequestMapping("/updateLikeNum")
    public String updateLikeNum(@RequestParam("id") int id,@RequestParam("likeNum") int likeNum){
        try {
            String s = pcUserService.updateLikeNum(id, likeNum);
            return s;
        }catch (Exception e){
            return "100";
        }
    }






}
